 
package com.ctsi.commons.conversion;

/** 类型转换接口 
 *
 * @param <S> 需要转换的类型
 * @param <T> 目标类型
 */
public interface Converter<S, T> {
    /** Returns <code>true</code> if this object can convert
     * <code>sourceClass</code> to <code>targetClass</code>.
     * <p>Implementations can accomodate class hierarchy ranges
     * by converting super classes or interfaces.</p>
     *
     * @param sourceClass The source <code>Class</code>
     * @param targetClass The target <code>Class</code>
     * @return <code>true</code> if this object can convert
     * <code>sourceClass</code> to <code>targetClass</code>.
     */
    boolean canConvert(Class<?> sourceClass, Class<?> targetClass);

    /** 转化 <code>obj</code> 为 <code>T</code>.
     *
     * @param obj 需要转换的对象 <code>Object</code>  
     * @return 转换为的 <code>Object</code>
     * @throws ConversionException
     */
    T convert(S obj) throws ConversionException;

    /** Converts <code>obj</code> to <code>T</code>.
     *
     * @param targetClass 需要转换为的 <code>Class</code> 类型
     * @param obj 需要转换的对象
     * @return 转换完成的 <code>对象</code>
     * @throws ConversionException
     */
    T convert(Class<? extends T> targetClass, S obj) throws ConversionException;

    /** Returns the source <code>Class</code> for this converter.
     *
     * @return The source <code>Class</code> for this converter
     */
    Class<?> getSourceClass();

    /** Returns the target <code>Class</code> for this converter.
     *
     * @return The target <code>Class</code> for this converter
     */
    Class<?> getTargetClass();
}
